home *** CD-ROM | disk | FTP | other *** search
- //
- // MiscParseTableFile.h -- functions and categories to parse files of
- // the format taken by *.addresses, PB.project, and others.
- // Written by Don Yacktman Copyright (c) 1994 by Don Yacktman.
- // Version 1.0. All rights reserved.
- //
- // This notice may not be removed from this source code.
- //
- // This object is included in the MiscKit by permission from the author
- // and its use is governed by the MiscKit license, found in the file
- // "LICENSE.rtf" in the MiscKit distribution. Please refer to that file
- // for a list of all applicable permissions and restrictions.
- //
-
- #import <objc/objc.h>
- @class MiscString;
- @class MiscDictionary;
-
- // We use a recursive descent parser to accomplish the parsing and
- // a recursive algorithm to write out the file contents. The file
- // is represented at the top level with a "MiscDictionary" object.
- // The keys are all NXAtoms (unique strings) and the values are all
- // objects. These objects can be MiscStrings, MiscLists, and
- // MiscDictionaries. In the file, a MiscList is represented by a
- // comma separated list of strings, dictionaries, or lists surrounded
- // by parenthesis (). A MiscDictionary is represented with a series
- // of key/value pairs (with the values again as strings, lists, and
- // dictionaries) surrounded by curly braces {}. Look at a PB.project
- // or a *.addresses file for examples of legal files. A good example is
- // /usr/template/user/Library/Addresses/Example.addresses/AddressBook.table
- // which contains examples of strings, lists, and dictionaries. The
- // BNF grammar below might help, too, assuming I wrote it out right...
-
- extern id MiscParseTableFile(MiscString *fileName);
- extern id MiscParseTableStream(NXStream *aStream);
-
- // These functions produce a file/stream parseable by the above.
- // They won't work if the data structre contains objects other than
- // MiscList, MiscDictionary, and MiscString, unless the objects
- // implement the method:
- // - writeASCIIToStream:(NXStream *)aStream;
- // Note that parsing will only return the listed object types, so
- // it is imperative that your implementation write out a properly
- // parseable text if you plan to read in the files using the
- // MiscParse...() routines listed above.
-
- extern int MiscWriteTableFile(MiscString *fileName, MiscDictionary *tableRoot);
- extern int MiscWriteTableStream(NXStream *aStream, MiscDictionary *tableRoot);
-
- /*
-
- Here is the BNF implemented by this code: (more or less accurate)
- Start parsing with the File non-terminal. ":=" to define non-terminals
- and <epsilon> is used to denote when a non-terminal can reduce to
- nothing (ie, it is not required).
-
- Literals (terminals) are given in single quotes '' and use the
- following:
- [] "any one of what is inside"
- * "zero or more of what preceeds"
- () used for grouping
- - "anything in between" (0-9 means "0123456789", etc.)
-
- File := Dictionary
-
- Dictionary := Dictionary Line
- Dictionary := Line
-
- Line := <epsilon>
- Line := String '=' Association ';' # The String is the hash key and is
- # always uniqued by the parser.
-
- Association := '{' Dictionary '}' # Keyed groups of objects
- Association := '(' List ')' # Groups of unkeyed objects
- Association := '{' '}' # These can be empty as well...
- Association := '(' ')'
- Association := String
-
- List := List ',' Association # List is comma separated group
- List := Association
-
- String := '"' Eliteral '"' # two types of string: quoted, non-q.
- String := Literal
-
- Literal := Literal '[A-Za-z0-9]' # what can be in a non-quoted string
- Literal := '[A-Za-z0-9]'
-
- Eliteral := Eliteral ELchar # what can be in a quoted string
- Eliteral := ELchar # the main diff is allowing white-
- # space and "\" quoted characters
-
- ELchar := '[Any char except '\' and '"']'
- ELchar := '\' '\'
- ELchar := '\' '"'
- ELchar := '\' 't'
- ELchar := '\' 'n'
- ELchar := '\' 'r'
- ELchar := '\' '0' 'x' '([0-9A-Fa-f])*' # hex constant
- ELchar := '\' '0' '[0-7]*' # octal constant
- ELchar := '\' '[1-9]' '[0-9]*' # decimal constant
-
- */
-